
<h1><span class="yiyi-st" id="yiyi-12">numpy.linalg.solve</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.solve.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.linalg.solve"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.linalg.</code><code class="descname">solve</code><span class="sig-paren">(</span><em>a</em>, <em>b</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/linalg/linalg.py#L296-L386"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">求解线性矩阵方程或线性标量方程组。</span></p>
<p><span class="yiyi-st" id="yiyi-15">计算良好确定的，即满秩线性矩阵方程<em class="xref py py-obj">ax = b</em>的“精确”解，<em class="xref py py-obj">x</em>。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-16">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-17"><strong>a</strong>：（...，M，M）array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-18">系数矩阵。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-19"><strong>b</strong>：{（...，M，），（...，M，K）}，array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-20">纵坐标或“因变量”值。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-21">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-22"><strong>x</strong>：{（...，M，），（...，M，K）} ndarray</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-23">解决方案a系统a x = b。</span><span class="yiyi-st" id="yiyi-24">返回形状与<em class="xref py py-obj">b</em>相同。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-25">上升：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-26"><strong>LinAlgError</strong></span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-27">如果<em class="xref py py-obj">a</em>是奇异或不是正方形。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-28">笔记</span></p>
<div class="versionadded">
<p><span class="yiyi-st" id="yiyi-29"><span class="versionmodified">版本1.8.0中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-30">广播规则适用，有关详细信息，请参阅<code class="xref py py-obj docutils literal"><span class="pre">numpy.linalg</span></code>文档。</span></p>
<p><span class="yiyi-st" id="yiyi-31">使用LAPACK程序_gesv计算解</span></p>
<p><span class="yiyi-st" id="yiyi-32"><em class="xref py py-obj">a</em>必须是正方形且满秩，即所有行（或等效地，列）必须是线性无关的；如果任一个不为真，则使用<a class="reference internal" href="numpy.linalg.lstsq.html#numpy.linalg.lstsq" title="numpy.linalg.lstsq"><code class="xref py py-obj docutils literal"><span class="pre">lstsq</span></code></a>计算系统/方程的最小二乘最佳“解”。</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-33">参考文献</span></p>
<table class="docutils citation" frame="void" id="r43" rules="none">
<colgroup><col class="label"><col></colgroup>
<tbody valign="top">
<tr><td class="label"><span class="yiyi-st" id="yiyi-34"><a class="fn-backref" href="#id1">[R43]</a></span></td><td><span class="yiyi-st" id="yiyi-35">G. Strang, <em>Linear Algebra and Its Applications</em>, 2nd Ed., Orlando, FL, Academic Press, Inc., 1980, pg. </span><span class="yiyi-st" id="yiyi-36">22.</span></td></tr>
</tbody>
</table>
<p class="rubric"><span class="yiyi-st" id="yiyi-37">例子</span></p>
<p><span class="yiyi-st" id="yiyi-38">求解方程系统<code class="docutils literal"><span class="pre">3</span> <span class="pre">*</span> <span class="pre">x0</span> <span class="pre">+</span> <span class="pre">x1</span> <span class="pre"> =</span> <span class="pre">9</span></code>和<code class="docutils literal"><span class="pre">x0</span> <span class="pre">+</span> <span class="pre">2</span> <span class="pre"></span> <span class="pre">x1</span> <span class="pre">=</span> <span class="pre">8</span></code>：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">3</span><span class="p">,</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">9</span><span class="p">,</span><span class="mi">8</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">linalg</span><span class="o">.</span><span class="n">solve</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([ 2.,  3.])</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-39">检查解决方案是否正确：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">allclose</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">x</span><span class="p">),</span> <span class="n">b</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>
